package lab;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

public class LabView extends BasicGame
{
	protected boolean[][] _map;
	protected Image _niv1;
	protected Image _wall;

	public LabView(String title)
	{
		super( title );
	}

	@Override
	public void render( GameContainer arg0 , Graphics arg1 ) throws SlickException
	{

		for ( int i = 0; i < _map[0].length; i++ )
		{
			for ( int j = 0; j < _map.length; j++ )
			{
				if ( _map[i][j] )
				{
					_wall.draw( 100 + i * _wall.getWidth() , 100 + j * _wall.getHeight() );
				}
				else
				{
					_niv1.draw( 100 + i * _niv1.getWidth() , 100 + j * _niv1.getHeight() );
				}
			}
		}

	}

	@Override
	public void init( GameContainer arg0 ) throws SlickException
	{
		calculate();
		_niv1 = new Image( "data/astar.bmp" );
		_wall = new Image( "data/wall.bmp" );

	}

	@Override
	public void update( GameContainer gc , int arg1 ) throws SlickException
	{
		Input input = gc.getInput();
		if ( input.isKeyPressed( Input.KEY_A ) )
		{
			calculate();
		}
	}

	public void calculate()
	{
		_map = new GenerateurLab().getlabyrinthe();
	}

}
